<?php
class FabricModel extends BaseModel
{
    var $table  = 'fabric';
    var $prikey = 'fabric_id';
    var $_name  = 'fabric';
	
    var $_relation = array(
		'has_sample' => array(
			'model' => 'sample',
			'type' => HAS_MANY,
			'foreign_key' => 'fabric_id',
		),
	);
	
    function unique($fabric_name, $fabric_id = 0)
    {
        $conditions = "fabric_name = '" . $fabric_name . "' AND fabric_id != ".$fabric_id."";
        return count($this->find(array('conditions' => $conditions))) == 0;
    }
}
?>